// index.js
// 获取应用实例
const app = getApp()
import {
	article,
	position,
} from '../../api/apiData'
var pageNum1 = 1; //页码
Page({
	data: {
		navList: [{
				url: "/pages/npcNews/index",
				src: "/images/grid-1.png",
				name: "工作动态"
			},
			{
				url: "/pages/study/nav?type=1",
				src: "/images/grid-2.png",
				name: "交易信息"
			},
			{
				url: "/pages/study/index?type=2",
				src: "/images/grid-3.png",
				name: "政策法规"
			},
			{
				url: "/pages/workManage/index",
				src: "/images/grid-4.png",
				name: "办事指南"
			}
		],
		loadMoreText: '加载中...', //底部文字
		list: [],
		banner: ''

	},

	onLoad() {
		this.getList(1)
		// banner
		position.content.detail({
			position_id: 1
		}, res => {
			if (res.code == 1) {
				this.setData({
					banner: res.data.path
				})
			}
		})
	},
	// 获取列表
	getList(page) {
		var that = this
		article.lists({
			page: page,
			size: 20,
			channel_id: 1,
			is_index:1
		}, res => {
			that.setData({
				total: res.data.total
			})
			if (res.data.list.length > 0) {
				that.setData({
					list: that.data.list.concat(res.data.list) //合并数据
				})
				if (11 > res.data.list.length > 0) {
					that.setData({
						loadMoreText: '' //没有更多了
					})
				}

			} else {
				if (page !== 1) {
					that.setData({
						loadMoreText: '暂无数据'
					})
				} else {
					that.setData({
						list: [],
						loadMoreText: '暂无数据'
					})
				}
			}
			wx.stopPullDownRefresh();
		})
	},
	onShow() {
		// this.getTabBar().init();
	},
	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {
		pageNum1 = 1
		this.setData({
			list: [],
		});
		this.getList(1)
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {
		pageNum1 += 1;
		this.getList(pageNum1)
	},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})